const express = require('express');
const bodyParser = require('body-parser');

const app = express();
const port = 3000;
let contacts = [];

app.use(bodyParser.json());

app.post('/add', (req, res) => {
    const contact = `${req.body.name}, ${req.body.address}, ${req.body.phone}`;
    contacts.push(contact);
    res.send('Contact added successfully.');
});

app.get('/view', (req, res) => {
    res.send(contacts.join('\n'));
});

app.listen(port, () => {
    console.log(`Server running at http://localhost:${port}`);
});